package cn.zcscloud.mall.controller;

import cn.zcscloud.mall.common.R;
import cn.zcscloud.mall.mbg.model.OmsOrder;
import cn.zcscloud.mall.mbg.model.OmsOrderSetting;
import cn.zcscloud.mall.service.OmsOrderSettingService;
import cn.zcscloud.mall.vo.MoneyInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/orderSetting")
public class OmsOrderSettingController {
    @Autowired
    private OmsOrderSettingService orderSettingService;

    //修改订单设置
    @PostMapping("/update/{id}")
    public R updateOrderSetting(@RequestBody OmsOrderSetting orderSetting, @PathVariable("id") Long id) {
        LambdaQueryWrapper<OmsOrderSetting> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OmsOrderSetting::getId, id);
        OmsOrderSetting setting = orderSettingService.getOne(queryWrapper);
        BeanUtils.copyProperties(orderSetting,setting,"id");
        orderSettingService.updateById(setting);
        return R.success("修改成功!", null);
    }

    //获取订单设置
    @GetMapping("/{id}")
    public R getOrderSetting(@PathVariable("id") Long id) {
        OmsOrderSetting orderSetting = orderSettingService.getById(id);
        return R.success(orderSetting);
    }
}
